package com.fruit.dao.impl;

import com.fruit.dao.FruitDao;
import com.fruit.pojo.Fruit;
import com.myssm.basedao.BaseDAO;

import java.util.List;

public class FruitDaoImpl extends BaseDAO<Fruit> implements FruitDao {

    @Override
    public List<Fruit> getFruitList() {
        return super.executeQuery("select * from t_fruit");

    }

    @Override
    public void addFruit(Fruit fruit) {
        String sql = "insert into t_fruit values(0,?,?,?,?)";
        super.executeUpdate(sql, fruit.getFname(), fruit.getPrice(),
                fruit.getFcount(), fruit.getRemark());
    }

    @Override
    public void updateFruit(Fruit fruit) {
//        String sql = "update t_fruit set fname = ?,price = ?,fcount = ?,remark=? where fid = ?";
//        super.executeUpdate(sql, fruit.getFname(),
//                fruit.getPrice(), fruit.getFcount(), fruit.getRemark(), fruit.getFid());

        String sql = "update t_fruit set fname = ? , " +
                "price = ? , fcount = ? , remark = ? " +
                "where fid = ? " ;
        super.executeUpdate(sql,fruit.getFname(),
                fruit.getPrice(),fruit.getFcount(),
                fruit.getRemark(),fruit.getFid());
    }

    @Override
    public Fruit getFruitByFid(Integer fid) {
        String sql = "select * from t_fruit where fid = ?";
        return super.load(sql, fid);
    }

    @Override
    public void delFruit(Integer fid) {
        String sql = "delete from t_fruit where fid = ?";
        super.executeUpdate(sql, fid);
    }
}
